const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    fenxiangzhuan: {
      show: false,
      width: '118rpx;',
      height: '100rpx;',
      bottom: '212rpx;',
      top: '16rpx'
    }
  },
  backto: function (e) {
    var pages = getCurrentPages()
    
    var last = pages[pages.length - 2].route;
    if (last == 'pages/quan/add' ){
      wx.switchTab({
        url: '/pages/quan/quan',
      })
    }
    else if (last == 'pages/index/common/add'){
      wx.switchTab({
        url: '/pages/add/add',
      })
    }
    else{
      wx.navigateBack({})
    }
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.ihttpGet('https://www.58zltc.com/api.php/Coupon', res=>{
      this.setData({
        list: res.data
      })
    })
  },
  getCoupon: function (e) {
    let that = this;
    const id = e.currentTarget.dataset.id;
    var post_data = {};
    post_data.coupon_id = id;
    post_data.openid = app.globalData.openid;
    app.ihttpPost("https://www.58zltc.com/api.php/Coupon/getCoupon", post_data, function (res) {
      app.iModel(res.data.err_msg);
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    app.confirmCommission()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let that = this;
    return {
      title: '优惠券',
      path: '/pages/shop/coupon/coupon' + '?fenxiang=' + app.globalData.openid + '&fWid=' + that.data.list[0].wid,
      success: function (res) {
        var a = that.data.fenxiangzhuan
        a.show = false
        that.setData({
          fenxiangzhuan: a
        })
        // 转发成功
        wx.showToast({
          title: '转发成功！',
        })
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  changeFXZ: function () {
    var that = this;
    var a = that.data.fenxiangzhuan
    a.show ? a.show = false : a.show = true
    that.setData({
      fenxiangzhuan: a
    })
  }
})